<script language="JavaScript" type="text/javascript">
	{literal}
	var RefineSearchBlock = {
		show: function (curID) {
			CookieHelper.set(curID, 'v');
			var obj = $("#"+curID);
			obj.next(".refine_block").show();
			obj.children(".refine_icon").html("[-]");
			obj.children(".refine_icon").addClass("less");
			obj.children(".refine_icon").removeClass("more");
		},

		hide: function (curID) {
			CookieHelper.set(curID, 'h');
			var obj = $("#"+curID);
			obj.next(".refine_block").hide();
			obj.children(".refine_icon").html("[+]");
			obj.children(".refine_icon").addClass("more");
			obj.children(".refine_icon").removeClass("less");
		},

		showHide: function (curID)	{
			if ($("#"+curID).next(".refine_block").css("display") == "block") {
				this.hide(curID);
			} else {
				this.show(curID);
			}
		},

		restore: function (curID, hideDef) {
			if (CookieHelper.get(curID) == 'h') {
				this.hide(curID);
			} else if (CookieHelper.get(curID) == 'v') {
				this.show(curID);
			} else {
				if (hideDef) {
					this.hide(curID);
				} else {
					this.show(curID);
				}
			}
		}
	}
	var CookieHelper = {
		get: function (rname)	{
			var tmp = "" + document.cookie;
			var result = "";
			while (tmp.length) {
				splitter = tmp.indexOf(";");
				if (splitter < 0) {
					splitter = tmp.length + 1;
				}
				subject = tmp.substring(0, splitter);
				if (decodeURIComponent($.trim(subject.substring(0, subject.indexOf('=')))) == rname) {
					result = subject.substring(subject.indexOf('=') + 1, subject.length);
				}
				tmp = tmp.substring(splitter + 1, tmp.length);
			}
			return result;
		},

		set: function (name, value) {
			document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + "; path=/;";
		}
	}
	function refineBlockBinder(textLess, textMore) {
		$(".refine_button").click(function() {
			RefineSearchBlock.showHide($(this).attr("id"));
		});

		$(".block_values_button").click(function(){
			var butt = $(this);
			$(this).prev(".block_values").slideToggle("normal", function() {
				if ($(this).css("display") == "block") {
					butt.html(textLess);
				} else {
					butt.html(textMore);
				}
			});
		});
	}
	{/literal}
</script>

{if !empty($currentSearch)}
	<table cellpadding="0" cellspacing="0" id="currentSearch">
		<thead>
			<tr>
				<th class="tableLeft">&nbsp;</th>
				<th>&nbsp;[[Current Search]]:</th>
				<th class="tableRight">&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td colspan="3">
					{capture name="urlParams"}searchId={$searchId}&amp;action=undo{if $show_brief_or_detailed}&amp;show_brief_or_detailed={$show_brief_or_detailed}{/if}&amp;view={$view}{/capture}
					{foreach from=$currentSearch item="fieldInfo" key="fieldID"}
						<div class="separate-div">
							<div class="currentSearch"><strong>[[{$fieldInfo.name}]]</strong></div>
							{foreach from=$fieldInfo.field item="fieldValue" key="fieldType"}
								{if $fieldType == 'monetary'}
									{foreach from=$fieldValue item="val" key="realVal" name="loopVal"}
										{if $smarty.foreach.loopVal.iteration%2 == 0}
											[[to]]
										{/if}
										<span class="curSearchItem">
											<a href="?{$smarty.capture.urlParams}&amp;param={$fieldID}&amp;type={$fieldType}&amp;value={$realVal|escape:'url'}">[[(undo)]]</a>
											{tr}{$val|escape:"html"}{/tr}
										</span>
									{/foreach}
								{else}
									{foreach from=$fieldValue item="val" key="realVal"}
										<span class="curSearchItem">
											<a href="?{$smarty.capture.urlParams}&amp;param={$fieldID}&amp;type={$fieldType}&amp;value={$realVal|escape:'url'}">[[(undo)]]</a>
											{tr}{$val|escape:"html"}{/tr}
										</span>
									{/foreach}
								{/if}
							{/foreach}
						</div>
					{/foreach}
					<br/>
				</td>
			</tr>
		</tbody>
	</table>
	<br/>
{/if}

{capture name="trLess"}&#60;&nbsp;<span>[[Less]]</span>{/capture}
{capture name="trMore"}&#62;&nbsp;<span>[[More]]</span>{/capture}

{if !empty($refineFields)}
	<table cellpadding="0" cellspacing="0" width="100%" id="refineResults">
		<thead>
			<tr>
				<th class="tableLeft">&nbsp;</th>
				<th>[[Refine Results]]</th>
				<th class="tableRight">&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td colspan="3">
					{capture name="urlParams"}searchId={$searchId}&amp;action=refine{if $show_brief_or_detailed}&amp;show_brief_or_detailed={$show_brief_or_detailed}{/if}&amp;view={$view}{/capture}
					{foreach from=$refineFields item=refineField}
						<div class="separate-div">
							{if $refineField.show && $refineField.count_results}
								<div class="refine_button" id="{$refineField.field_name}"><div class="refine_icon">[+]</div><strong>[[{$refineField.caption}]]</strong></div>
								<div class="refine_block" style="display: none">
									{foreach from=$refineField.search_result item=val name=fieldValue}
										{if $smarty.foreach.fieldValue.iteration == 6}
											<div class="block_values"  style="display: none">
										{/if}
										{capture name="refineFieldCriteria"}{$refineField.field_name}{if in_array($refineField.type, array('string'))}[multi_like_and]{else}[multi_like]{/if}[]={if $val.sid}{$val.sid}{else}{$val.value|escape:'url'}{/if}{/capture}
										<div class="refineItem">
											<a href="?{$smarty.capture.urlParams}&amp;{$smarty.capture.refineFieldCriteria}">{tr}{$val.value|escape:'html'}{/tr}</a>{if empty($refineField.criteria)}&nbsp;({$val.count}){/if}
										</div>
									{/foreach}
									{if $smarty.foreach.fieldValue.total >= 6}
										</div><div class="block_values_button">{$smarty.capture.trMore}</div>
									{/if}
								</div>
								<script type="text/javascript">RefineSearchBlock.restore('{$refineField.field_name}',true); </script>
							{/if}
						</div>
					{/foreach}
					<br/>
				</td>
			</tr>
		</tbody>
	</table>
{/if}

<script type="text/javascript" language="JavaScript">
	refineBlockBinder("{$smarty.capture.trLess|escape:"quotes"}", "{$smarty.capture.trMore|escape:"quotes"}");
</script>
